#include "guish.hpp"
#ifndef PROCESSMANAGER_HPP
#define PROCESSMANAGER_HPP

class ProcessManager
{
public:
	ProcessManager();
	~ProcessManager();
	
	void takeLock();
	void releaseLock();
	
	void checkChildren();
	// Precondition: This thread holds the lock (with takeLock())
	void registerNewProcess(Process *process);
	
	bool processIsFinished(int pid);
	int getResult(int pid);
	void forgetResult(int pid);
	
private:
	void finishProcess(int pid, int status);
	
	pthread_mutex_t lock;
	
	map<int, Process*> processes;
	map<int, int> results;
};

extern ProcessManager *processManager;

#endif
